<?php

if(!function_exists("list_rule")){
    function list_rule($moduleId,$page_arg=0){
        $file_ext = "<fileExt>";
        $catdir="<catdir>";
        $index="<index>";
        $catid="<catId>";
        $catname="<catName>";
        $itemid="<articleId>";
        $mix_itemid="<mix_articleId>";
        $page="<page>";
        $prefix = "<prefix>";
        $year = "<year>";
        $month = "<month>";
        $day = "<day>";

        $moduleListHtml = setting("moduleListHtml", $moduleId);
        $urlid = $moduleListHtml ? setting("htmlListUrlRule", $moduleId) : setting("listUrlRule", $moduleId);
        $ext = $moduleListHtml ? 'htm' : 'php';
        $url = config("setting_data.listUrlRule.{$ext}.list.{$urlid}");
        $url = $page_arg ? $url['page'] : $url['index'];
        $listurl="";
        eval("\$listurl = \"$url\";");
        if(substr($listurl, 0, 1) == '/') {
            $listurl = substr($listurl, 1);
        }
        return $listurl;
    }
}

if(!function_exists("item_rule")){
    function item_rule($moduleId){
        $file_ext = "<fileExt>";
        $catdir="<catdir>";
        $index="<index>";
        $catid="<catId>";
        $catname="<catName>";
        $itemid="<articleId>";
        $mix_itemid="<mix_articleId>";
        $page="<page>";
        $prefix = "<prefix>";
        $year = "<year>";
        $month = "<month>";
        $day = "<day>";

        $moduleConHtml = setting("moduleConHtml", $moduleId);
        $urlid = $moduleConHtml ? setting("htmlConUrlRule", $moduleId) : setting("conUrlRule", $moduleId);
        $ext = $moduleConHtml ? 'htm' : 'php';
        $url = config("setting_data.listUrlRule.{$ext}.item.{$urlid}");
        $url = $url['index'];

        $itemurl="";
        eval("\$itemurl = \"$url\";");
        if(substr($itemurl, 0, 1) == '/') {
            $itemurl = substr($itemurl, 1);
        }
        return $itemurl;
    }
}

if(!function_exists("listurl")){
    /**
     * 获取列表url
     */
    function listurl($moduleId,$categoryId,$page=0){
        $categoryData=($moduleId && $categoryId)?category('module',$moduleId,$categoryId):array();

        $file_ext = siteSetting("fileExtension");
        $catdir=$categoryData["catDir"];
        $index=siteSetting("index_filename");
        $catid=$categoryData["id"];
        $catname=$categoryData["name"];
        $moduleListHtml = setting("moduleListHtml", $moduleId);
        $prefix = setting("htm_list_prefix", $moduleId);

        $urlid = $moduleListHtml ? setting("htmlListUrlRule", $moduleId) : setting("listUrlRule", $moduleId);
        $ext = $moduleListHtml ? 'htm' : 'php';
        $url = config("setting_data.listUrlRule.{$ext}.list.{$urlid}");
        $url = $page ? $url['page'] : $url['index'];

        $listurl="";
        eval("\$listurl = \"$url\";");
        if(substr($listurl, 0, 1) == '/') {
            $listurl = substr($listurl, 1);
        }
        return $listurl;
    }
}

if(!function_exists("itemurl")){
    /**
     * 获取文章url
     */
    function itemurl($articleData){
        $file_ext = siteSetting("fileExtension");
        $index=siteSetting("index_filename");
        $prefix = setting("htm_list_prefix", $articleData["moduleId"]);
        $catid=$articleData["categoryId"];
        $categoryData=$articleData["categoryId"]?category('module',$articleData["moduleId"],$articleData["categoryId"]):array();
        $catdor=$categoryData?$categoryData["catDir"]:"";
        $itemid = $articleData['id'];
        $addTime = $articleData['addTime'];
        $year = date("Y",$addTime);
        $month = date("m",$addTime);
        $day = date("d",$addTime);
        $mix_itemid = app("yifangConfusionCode")->enCode($articleData["id"]);

        $moduleConHtml = setting("moduleConHtml", $articleData["moduleId"]);
        $urlid = $moduleConHtml ? setting("htmlConUrlRule", $articleData["moduleId"]) : setting("conUrlRule", $articleData["moduleId"]);
        $ext = $moduleConHtml ? 'htm' : 'php';
        $url = config("setting_data.listUrlRule.{$ext}.item.{$urlid}");
        $url = $url['index'];

        $itemurl="";
        eval("\$itemurl = \"$url\";");
        if(substr($itemurl, 0, 1) == '/') {
            $itemurl = substr($itemurl, 1);
        }
        return $itemurl;
    }
}


